<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>使用call和apply借用其他原型链上的方法</title>
</head>
<body>
    <script>
        let hd = {
            data:[1,4,5,6,5,8,2]
        };

        Object.setPrototypeOf(hd,{
            max(data){
                console.log(data);
                return data.sort((a,b) => b-a)[0];
            }
        });
        console.log(hd.max(hd.data));


        let hdms = {
            lessons:{css:88,js:99,html:89}
        };
        console.log(hd.max.call(null,Object.values(hdms.lessons)));



        // 借用Math函数中的max进行优化
        console.log(Math.max.apply(null,hd.data));
        console.log(Math.max.call(null,...hd.data));
        console.log(Math.max.apply(null,Object.values(hdms.lessons)));
        console.log(Math.max.call(null,...Object.values(hdms.lessons)));
    </script>
</body>
</html>